/* QualifiedAssociation.m:
 * You may freely copy, distribute, and reuse the code in this example.
 * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
 * fitness for any particular use.
 *
 * Written by Mai Nguyen, NeXT Developer Support
 *
 */

#import "QualifiedAssociation.h"

@implementation QualifiedAssociation

/*  initialization method.
 */

- (QualifiedAssociation *)initAndReplaceAssociationTo:(DBFetchGroup *)detailFG
{
	DBModule * 				dbModule;
	DBAssociation * 		dbAssociation;
	DBExpression *			dbExpression;
	DBFetchGroup *			masterFetchGroup;
		
	/* Get a hold of the association from master fetchgroup to detail
	 * fetchgroup
	 */
	dbModule = [detailFG module];
	dbAssociation = [dbModule associationForObject:detailFG];
	dbExpression = [dbAssociation expression];
	masterFetchGroup = [dbAssociation fetchGroup];
		/* Remove the association from the master fetchgroup
		 */
	[masterFetchGroup removeAssociation:dbAssociation];
	[self initFetchGroup:masterFetchGroup
		expression: dbExpression
		destination: detailFG ];
			
	[masterFetchGroup addAssociation:self];
	
		/* Free old association */
	[dbAssociation free];
	return self;
}

- setValue:value
{
	[[self destination] fetchContentsOf:value usingQualifier:dbQualifier];
	return self;
}

- setQualifier: qualifier
{
	dbQualifier = (DBQualifier *)qualifier;
	return self;
}

- qualifier
{
	return dbQualifier;
}


@end
